#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define rep(x,l,r) for(int x=l;x<=r;x++)

#define pii pair<int,int>
#define mp make_pair
#define X first
#define Y second

using namespace std;
const int N=5e5+10,M=1e6+10;

ll n,k,x,y,b[M],nn,lst,mn,c,a[N],num[M],now,cnt;vector<int>g[N],ans;priority_queue<pii,vector<pii>,greater<pii>>q; 

int main(){
	
	freopen("list.in","r",stdin);
	freopen("list.out","w",stdout);

	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>n;
	rep(i,1,n){cin>>k;while(k--)cin>>x,g[i].pb(x),b[++nn]=x;}
	cin>>c;rep(i,1,n)cin>>a[i],a[i]*=i;sort(b+1,b+nn+1);nn=unique(b+1,b+nn+1)-b-1;
	rep(i,1,n)rep(j,0,(int)g[i].size()-1){
		x=lower_bound(b+1,b+nn+1,g[i][j])-b;if(j)q.push(mp(g[i][j]-lst+1,x));
		cnt++;now+=c;now-=a[num[x]];now+=a[++num[x]];lst=g[i][j];g[i][j]=x;
	}
	mn=now;ans.pb(1);lst=1;
	while(!q.empty()){
		x=q.top().X;now+=cnt*(x-lst)*c;lst=x;
		while(!q.empty()&&q.top().X==x)y=q.top().Y,q.pop(),now-=c,cnt--,now-=a[num[y]],now+=a[--num[y]];
		if(now<mn)mn=now,ans.clear(),ans.pb(x);else if(now==mn)ans.pb(x);
	}
	cout<<mn<<" "<<ans.size()<<"\n";for(int x:ans)cout<<x<<" ";cout<<"\n";
	
	return 0;
}
